package cn.com.df;
import java.text.SimpleDateFormat;
import org.apache.log4j.Logger;
import smscommon.ComFun;
import smscommon.SmsClient;
import smsmessage.sms.DELIVER;
import smsmessage.sms.FlashSubmit;
import smsmessage.sms.SUBMIT;
import smsmessage.sms.SUBMIT_RESP;


/**
 * �������ŵ��·�
 * @author Administrator
 *
 */
public class MainFlashSmsDemo1 {

	public static void main(String[] args){
		SmsClient.getInstance();
//		smsClient.pause();
		new SubmitFlashSms1().start();
		new FindDeliverFlashSms1().start();
	}
}

class SubmitFlashSms1 extends Thread {
	private static Logger logger = Logger.getLogger(SubmitFlashSms1.class);
	SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HH:mm:ss");

	public void run() {
		for (int i = 0; i < 1; i++) {
			try {				
				FlashSubmit mt = new FlashSubmit();	
				mt.setDestID("13810000000"); // �û�����
				mt.setMsgContent("���Ų���");// ��������
				mt.setPriority(1);//1���ȼ��У�0�ͣ�2��
				String retVal = "1";
				while ("1".equals(retVal) || "2".equals(retVal)
						|| "3".equals(retVal)) {
					Thread.sleep(1000);
					retVal = mt.sendSMS();				
					if ("1".equals(retVal)) {						
//						logger.error("�·����������.");
					} else if ("2".equals(retVal)) {
//						logger.error("û�н�bl��");
					} else if ("3".equals(retVal)) {
//						logger.error("������趨ֵ");
					}else{
						logger.info("��ҵ������Ϣ��ʶ ["+retVal+"]��"
								+"Դ���� ["+mt.getSrcID()+"]��"
								+"Ŀ�ĺ��� ["+mt.getDestID()+"]��"
								+"�������� ["+mt.getMsgContent()+"]");						
					}
				}						
			} catch (Exception e) {
				logger.error(this, e);
			}
		}
	}
}


class FindDeliverFlashSms1 extends Thread {
	private static Logger logger = Logger.getLogger(FindDeliverFlashSms1.class);
	public void run() {
		DELIVER deliver = new DELIVER();
		while (true) {
			if ((deliver = ComFun.getSMS()) != null) {
				if (deliver.getMsgFlag() == 1) {
					
					logger.info("-״̬����: " 
							+ "��ҵ������Ϣ��ʶ ["	+ deliver.getMsgContent() + "]+" 
							+ "���Ž���������� ["+ deliver.getReserve() + "]+" 
							+ "����״̬ ["+ deliver.getReportState() + "]\n");
				} else {
					
					logger.info("-���ж��ţ�" + "����Դ���� [" + deliver.getSrcID()
							+ "]+" + "����Ŀ�ĺ��� [" + deliver.getDestID() + "]+"
							+ "������Ϣ���� [" + deliver.getMsgContent() + "]\n");
				}

			} else {
				try {
					Thread.sleep(1000);
				} catch (Exception e) {
					logger.error(e);
				}
			}
		}
	}
}
